crossvalidate.number <- function(dataframe,dv, iv, number){
		
		form <- paste(dv,iv,sep="~")
		spans <- seq(from=.2, to=1, length=100)
		number.list <- seq(from=1, to=number, by=1)
		dataframe$include <- sample(1:number, dim(dataframe)[1], replace=TRUE)
		errors <- matrix(data=NA, nrow=length(spans), ncol=length(number.list))
		mse.span <- NA
		
		for(i in 1:length(number.list)){
			outsample <- subset(dataframe, dataframe$include==number.list[i] & !is.na(dataframe[,dv]))
			insample <- subset(dataframe, dataframe$include!=number.list[i] & !is.na(dataframe[,dv]))
				
				for(j in 1:length(spans)){			
				mse.span[j] <- sum((predict(loess(as.formula(form), data=insample, span=spans[j]), newdata=outsample) - outsample[,dv])^2, na.rm=TRUE)/length(outsample[,dv])
				}
		
		errors[,i] <- mse.span
		}
		
		errors <- as.data.frame(errors)
		means <- apply(X=errors, MARGIN=1, FUN=mean)
		errors$means <- means
		errors$spans <- spans
		return(errors)
}